package com.ycsj.goldmedalnewconcept.activity;

import io.rong.imkit.RongIM;
import io.rong.imlib.model.Group;
import io.rong.imlib.model.UserInfo;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.bean.ConversationListResq;
import com.ycsj.goldmedalnewconcept.bean.ConversationUserinfoResp;
import com.ycsj.goldmedalnewconcept.bean.ResreshHeadimgRsq;
import com.ycsj.goldmedalnewconcept.bean.friendInfo;
import com.ycsj.goldmedalnewconcept.constant.ConfigConstant;
import com.ycsj.goldmedalnewconcept.constant.Constant;
import com.ycsj.goldmedalnewconcept.constant.NetConstant;
import com.ycsj.goldmedalnewconcept.utils.BitmapCompressor;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.utils.SPUtils;
import com.ycsj.goldmedalnewconcept.R;

//会话界面 顶部资料
public class MineConversationInfo extends BaseJpStarActivity {

	private TextView tv_main_back;
	private TextView tv_title_main;
	private TextView tv_info_name;
	private TextView tv_info_age;
	private TextView tv_info_class;
	private TextView tv_info_grade;
	private TextView tv_info_number;
	private TextView tv_info_school;
	private TextView tv_info_sex;
	private TextView textView1;
	protected static final int CHOOSE_PICTURE = 0;
	protected static final int TAKE_PICTURE = 1;
	private static final int CROP_SMALL_PICTURE = 2;
	protected static Uri tempUri;
	private int mWH = 360;// 单位dp
	private static final int PICTURE_REQUEST_CODE = 444;
	private static final int CAMERA_REQUEST_CODE = 222;
	String filePath = null;
	private String disableGroup;
	private String account;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_mineconversitioninfo);

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			setTranslucentStatus(true);
		}
		SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setStatusBarTintResource(R.color.base_color);

		disableGroup = SPUtil.getString(MineConversationInfo.this,
				"disableGroup", "");
		account = SPUtil.getString(MineConversationInfo.this, "account", "");
		init();
	}

	private ArrayList<String> listurl;

	private void init() {
		tv_main_back = (TextView) findViewById(R.id.tv_main_back);
		tv_title_main = (TextView) findViewById(R.id.tv_title_main);
		tv_info_name = (TextView) findViewById(R.id.tv_info_name);
		tv_info_age = (TextView) findViewById(R.id.tv_info_age);
		tv_info_class = (TextView) findViewById(R.id.tv_info_class);
		tv_info_grade = (TextView) findViewById(R.id.tv_info_grade);
		tv_info_number = (TextView) findViewById(R.id.tv_info_number);
		tv_info_school = (TextView) findViewById(R.id.tv_info_school);
		tv_info_sex = (TextView) findViewById(R.id.tv_info_sex);
		textView1 = (TextView) findViewById(R.id.textView1);
		textView2 = (TextView) findViewById(R.id.textView2);

		imageView2 = (ImageView) findViewById(R.id.imageView2);
		// if("".equals(getIntent().getStringExtra("userInfo"))){

		userInfo = getIntent().getStringExtra("userInfo");
		// OkHttpClient mOkHttpClient = new OkHttpClient();
		// // 创建一个Request
		// final Request request = new
		// Request.Builder().url(NetConstant.ACCOUNTINFO+"/StudentInfo.aspx?account="+userInfo+"&u_c=1&usertoken=").build();
		// // new call
		// Call call = mOkHttpClient.newCall(request);
		// call.enqueue(callBack);

		OkHttpClient mOkHttpClient = new OkHttpClient();
		// mOkHttpClient.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		FormEncodingBuilder builder = new FormEncodingBuilder();
		builder.add("type", "5");
		Log.e("home",
				"c="
						+ SPUtil.getString(MineConversationInfo.this,
								"clickUserid", ""));
		Log.e("role",
				"role="
						+ SPUtil.getString(MineConversationInfo.this,
								"clickRole", ""));
		builder.add("c",
				SPUtil.getString(MineConversationInfo.this, "clickUserid", ""));
		builder.add("role",
				SPUtil.getString(MineConversationInfo.this, "clickRole", ""));
		builder.add("platform", "2");
		Request request = new Request.Builder()
				.url(Constant.SERVER_URL + "AccountMsg").post(builder.build())
				.build();
		mOkHttpClient.newCall(request).enqueue(callBack);

		Log.e("home", "userid" + userInfo);// SPUtils.getString(MineConversationInfo.this,
											// "onUserPortraitClickid")
		tv_title_main.setText("个人信息");
		tv_main_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		if (SPUtils.getString(MineConversationInfo.this,
				ConfigConstant.USERNAME).equals(userInfo)) {
			imageView2.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// Intent intent4 = new Intent(
					// Intent.ACTION_GET_CONTENT);
					// intent4.setType("image/*");// 选择图片类型
					// // 在onActivityResult中处理选择结果
					// startActivityForResult(intent4, PICTURE_REQUEST_CODE);
					showChoosePicDialog();
				}
			});
		} else {
			imageView2.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					// Toast.makeText(MineConversationInfo.this, "else",
					// 0).show();

					// Intent intent3 = new Intent(MineConversationInfo.this,
					// GetPicShowActivity.class);
					// intent3.putStringArrayListExtra("urllist", listurl);
					// intent3.putExtra("position",0);
					// startActivity(intent3);
					// if(listurl!=null){
					// Intent intent3 = new Intent(MineConversationInfo.this,
					// BigPicShowActivity.class);
					// intent3.putStringArrayListExtra("urllist", listurl);
					// intent3.putExtra("position",0);
					// startActivity(intent3);
					// }

				}
			});

		}

		tv_info_number.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (isMobile(textView2.getText().toString())) {

					final Dialog dialog = new Dialog(MineConversationInfo.this,
							R.style.MyDialog);
					// 设置它的ContentView
					dialog.setCanceledOnTouchOutside(true);
					dialog.setContentView(R.layout.dialog_call);
					TextView tv_call1 = (TextView) dialog
							.findViewById(R.id.tv_call1);
					TextView tv_call2 = (TextView) dialog
							.findViewById(R.id.tv_call2);

					tv_call1.setText("是否呼叫" + username);
					tv_call2.setText("电话为:" + textView2.getText().toString());

					Button dialog_button_cancel = (Button) dialog
							.findViewById(R.id.dialog_button_cancel);
					Button dialog_button_ok = (Button) dialog
							.findViewById(R.id.dialog_button_ok);

					dialog_button_cancel
							.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									dialog.cancel();
								}

							});

					dialog_button_ok.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							Intent intent = new Intent(Intent.ACTION_CALL, Uri
									.parse("tel:"
											+ tv_info_number.getText()
													.toString()));
							startActivity(intent);
						}

					});
					dialog.show();
				}
			}
		});

	}

	protected void showChoosePicDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("设置头像");
		String[] items = { "选择本地图片", "拍照" };
		builder.setNegativeButton("取消", null);
		builder.setItems(items, new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				switch (which) {
				case CHOOSE_PICTURE:
					Intent openAlbumIntent = new Intent(
							Intent.ACTION_GET_CONTENT);
					openAlbumIntent.setType("image/*");
					// Data = Uri.fromFile(new File(Environment
					// .getExternalStorageDirectory(), "image1.jpg"));
					startActivityForResult(openAlbumIntent, CHOOSE_PICTURE);
					break;

				case TAKE_PICTURE:
					Intent openCameraIntent = new Intent(
							MediaStore.ACTION_IMAGE_CAPTURE);
					tempUri = Uri.fromFile(new File(Environment
							.getExternalStorageDirectory(), "image.jpg"));
					openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
					startActivityForResult(openCameraIntent, TAKE_PICTURE);
					break;
				}
			}
		});
		builder.create().show();
	}

	private String username;
	private String user_headimg;
	Handler handler = new Handler();
	// Callback callBack=new Callback() {
	//
	// @Override
	// public void onResponse(Response arg0) throws IOException {
	// String json = arg0.body().string();
	// // 使用Gson把json解析成对象
	// // 1 得到gson对象
	//
	// Log.i("test", "userid"+json);
	//
	// Gson gson = new Gson();
	// // // 2 使用gson对象的方法
	// final MineConversitionInfoResp mineInfoResp = gson.fromJson(json,
	// MineConversitionInfoResp.class);
	//
	// username = mineInfoResp.username;
	// // tv_info_name.setText(mineInfoResp.username);
	// handler.postDelayed(new Runnable() {
	//
	// @Override
	// public void run() {
	// // TODO Auto-generated method stub
	//
	//
	// tv_info_number.setText(mineInfoResp.tel);
	// // tv_info_sex.setText(mineInfoResp.sex);
	// tv_info_age.setText(mineInfoResp.age);
	// tv_info_school.setText(mineInfoResp.school);
	// tv_info_grade.setText(mineInfoResp.grade);
	// tv_info_class.setText(mineInfoResp.CLASS);
	// textView2.setText(mineInfoResp.tel);
	// if("".equals(mineInfoResp.sex)){
	// textView1.setText(mineInfoResp.username);
	//
	// }else{
	// textView1.setText(mineInfoResp.username+"("+mineInfoResp.sex+")");
	// }
	//
	// if(!"".equals(mineInfoResp.user_headimg)){
	//
	// Picasso.with(MineConversationInfo.this).load(mineInfoResp.user_headimg).fit().into(imageView2);
	// }
	// }
	// }, 100);
	// listurl = new ArrayList<String>();
	// listurl.add(mineInfoResp.user_headimg);
	// String path = NetConstant.RefreshUserInfo;
	//
	// OkHttpClient mOkHttpClient = new OkHttpClient();
	// mOkHttpClient.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
	// FormEncodingBuilder builder = new FormEncodingBuilder();
	// builder.add("userid",SPUtils.getString(MineConversationInfo.this,
	// ConfigConstant.USERNAME));
	// builder.add("portraitUri",mineInfoResp.user_headimg);
	// Request request = new Request.Builder()
	// .url(path)
	// .post(builder.build()).build();
	//
	// mOkHttpClient.newCall(request).enqueue(callBackRefresh);
	// }
	//
	// @Override
	// public void onFailure(Request arg0, IOException arg1) {
	// // TODO Auto-generated method stub
	//
	// }
	// };
	Callback callBack = new Callback() {

		@Override
		public void onFailure(Request arg0, IOException arg1) {

		}

		@Override
		public void onResponse(Response arg0) throws IOException {
			String json = arg0.body().string();
			Log.e("test", json);
			Gson gson = new Gson();
			final ConversationUserinfoResp fromJson = gson.fromJson(json,
					ConversationUserinfoResp.class);
			
			handler.postDelayed(new Runnable() {

				@Override
				public void run() {

					if ("".equals(fromJson.sex)) {
						textView1.setText(fromJson.name);

					} else {
						if ("0".equals(fromJson.sex)) {
							textView1.setText(fromJson.name + "(女)");
						} else {
							textView1.setText(fromJson.name + "(男)");
						}
					}

					if (fromJson.tel != null && fromJson.tel.length() > 10) {

						// 隐藏电话号码
						if ("0".equals(disableGroup)
								&& fromJson.tel.length() > 10
								&& !account.equals(fromJson.tel)) {
							tv_info_number.setText(fromJson.tel.substring(0, 3)
									+ "*****"
									+ fromJson.tel.substring(8,
											fromJson.tel.length()));
							textView2.setText(fromJson.tel.substring(0, 3)
									+ "*****"
									+ fromJson.tel.substring(8,
											fromJson.tel.length()));
						} else {
							tv_info_number.setText(fromJson.tel);
							textView2.setText(fromJson.tel);
						}
						// tv_info_number.setText(fromJson.tel);
					}
					
					if(fromJson.school!=null&&!TextUtils.isEmpty(fromJson.school)){
						tv_info_school.setText(fromJson.school);
					}
					
					if(fromJson.grade!=null&&!TextUtils.isEmpty(fromJson.grade)){
						tv_info_grade.setText(fromJson.grade);
					}
					
					if(fromJson.classnum!=null&&!TextUtils.isEmpty(fromJson.classnum)){
						tv_info_class.setText(fromJson.classnum);
					}
					
					tv_info_age.setText(fromJson.birthday);
					Picasso.with(MineConversationInfo.this).load(fromJson.icon)
							.into(imageView2);
					listurl = new ArrayList<String>();
					listurl.add(fromJson.icon);

				}
			}, 10);

		}

	};
	private ImageView imageView2;
	private TextView textView2;

	/**
	 * 手机号验证
	 * 
	 * @param str
	 * @return 验证通过返回true
	 */
	public static boolean isMobile(String str) {
		Pattern p = null;
		Matcher m = null;
		boolean b = false;
		p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号
		m = p.matcher(str);
		b = m.matches();
		return b;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case TAKE_PICTURE:
				startPhotoZoom(tempUri);
				break;
			case CHOOSE_PICTURE:
				Uri uri = data.getData();
				Bitmap bitmap = null;
				String imgPath = null;
				ContentResolver resolver = this.getContentResolver();
				String[] columns = { MediaStore.Images.Media.DATA };
				Cursor cursor = null;
				cursor = resolver.query(uri, columns, null, null, null);
				imgPath = uri.getPath();
				if (!TextUtils.isEmpty(imgPath) && imgPath.contains(":")) {
					String imgIndex = imgPath.split(":")[1];
					cursor = resolver.query(
							MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
							columns, "_id=?", new String[] { imgIndex }, null);
				}
				if (null != cursor && cursor.moveToFirst()) {
					int columnIndex = cursor.getColumnIndex(columns[0]);
					imgPath = cursor.getString(columnIndex);
					cursor.close();
					String filePath = imgPath;
				}
				if (!TextUtils.isEmpty(imgPath)) {
					bitmap = genBitmap(imgPath);
					imageView2.setImageBitmap(bitmap);
					upload();
				}
				break;
			case CROP_SMALL_PICTURE:
				if (data != null) {
					setImageToView(data);
				}
				break;
			}
		}
	}

	/**
	 * @param picdata
	 */
	protected void setImageToView(Intent data) {
		Bundle extras = data.getExtras();
		if (extras != null) {
			Bitmap photo = extras.getParcelable("data");
			imageView2.setImageBitmap(photo);
			try {
				saveFile(photo, "headimg.jpg");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			upload();
		}
	}

	/**
	 * 
	 * @param uri
	 */
	protected void startPhotoZoom(Uri uri) {
		if (uri == null) {
			Log.i("tag", "The uri is not exist.");
		}
		tempUri = uri;
		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(uri, "image/*");
		intent.putExtra("crop", "true");
		intent.putExtra("aspectX", 1);
		intent.putExtra("aspectY", 1);
		intent.putExtra("outputX", 150);
		intent.putExtra("outputY", 150);
		intent.putExtra("return-data", true);
		startActivityForResult(intent, CROP_SMALL_PICTURE);
	}

	// protected void onActivityResult(int requestCode, int resultCode, Intent
	// data) {
	// super.onActivityResult(requestCode, resultCode, data);
	//
	// if (resultCode == RESULT_OK && data != null) {
	//
	// Uri uri = data.getData();
	//
	// Bitmap bitmap = null;
	//
	// if (null != uri) {
	// String imgPath = null;
	// ContentResolver resolver = this.getContentResolver();
	// String[] columns = { MediaStore.Images.Media.DATA };
	// Cursor cursor = null;
	// cursor = resolver.query(uri, columns, null, null, null);
	//
	// if (Build.VERSION.SDK_INT > 18)// 4.4以后文件选择发生变化，判断处理
	// {
	// // http://blog.csdn.net/tempersitu/article/details/20557383
	// if (requestCode == PICTURE_REQUEST_CODE)// 选择图片
	// {
	// imgPath = uri.getPath();
	// if (!TextUtils.isEmpty(imgPath)
	// && imgPath.contains(":")) {
	// String imgIndex = imgPath.split(":")[1];
	// cursor = resolver
	// .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
	// columns, "_id=?",
	// new String[] { imgIndex }, null);
	//
	// }
	// }
	// }
	// if (null != cursor && cursor.moveToFirst()) {
	// int columnIndex = cursor.getColumnIndex(columns[0]);
	// imgPath = cursor.getString(columnIndex);
	// cursor.close();
	// // Toast.makeText(MainActivity.this, imgPath, 0).show();
	// filePath = imgPath;
	// // Log.e("test", "1234" + filePath);
	// }
	// if (!TextUtils.isEmpty(imgPath)) {
	// bitmap = genBitmap(imgPath);
	// upload();
	// }
	// }
	//
	// else if (requestCode == CAMERA_REQUEST_CODE)// 拍照
	// {
	// // 拍照时，注意小米手机不会保存图片到本地，只可以从intent中取出bitmap, 要特殊处理
	// Object object = data.getExtras().get("data");
	// if (null != object && object instanceof Bitmap) {
	// bitmap = (Bitmap) object;
	// upload();
	// }
	// }
	// if (null != bitmap) {
	// }
	// }
	//
	//
	// }

	/** 通过给定的图片路径生成对应的bitmap */
	private Bitmap genBitmap(String imgPath) {
		Options options = new Options();
		// options.inJustDecodeBounds = true;

		// 将图片像素设置为低像素
		options.inDensity = DisplayMetrics.DENSITY_HIGH;
		// 降低图片质量 设置为16位
		options.inPreferredConfig = Config.RGB_565;

		BitmapFactory.decodeFile(imgPath, options);
		int imageWidth = options.outWidth;
		int imageHeight = options.outHeight;

		int widthSample = (int) (imageWidth / mWH);
		int heightSample = (int) (imageHeight / mWH);
		// 计算缩放比例
		// options.inSampleSize = widthSample < heightSample ? heightSample
		// : widthSample;
		// options.inSampleSize=2;
		if (imageWidth < 2048 || imageHeight < 2048) {
			options.inSampleSize = 1;
		} else if (imageWidth > 2048 || imageHeight > 2048) {
			options.inSampleSize = 4;
		}
		// options.inJustDecodeBounds = false;
		Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options);
		bitmap = BitmapCompressor.decodeSampledBitmapFromBitmap(bitmap,
				imageWidth / (options.inSampleSize * 5), imageHeight
						/ (options.inSampleSize * 5));

		try {
			saveFile(bitmap, "headimg.jpg");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return bitmap;
	}

	private HttpUtils httpUtils;
	private String url;
	private RequestParams params;

	public void upload() {
		httpUtils = new HttpUtils();
		url = NetConstant.ACCOUNTINFO + "/UserHeadImg.aspx";
		params = new RequestParams();

		params.addBodyParameter("account", SPUtils.getString(
				MineConversationInfo.this, ConfigConstant.USERNAME));
		params.addBodyParameter("usertoken", SPUtils.getString(
				MineConversationInfo.this, ConfigConstant.USERTOKEN));

		String path = getSDPath() + "/goldupload/" + "headimg.jpg";
		File f = new File(path);
		// Log.e("test", "2234" + path);
		String[] split = path.split("\\/");
		String name = split[split.length - 1];
		params.addBodyParameter(name, f);
		params.addBodyParameter("fileinfo", name);

		httpUtils.send(HttpMethod.POST, url, params, callBackHeadimg);
	}

	/**
	 * 保存文件
	 * 
	 * @param bm
	 * @param fileName
	 * @throws IOException
	 */
	public void saveFile(Bitmap bm, String fileName) throws IOException {
		String path = getSDPath() + "/goldupload/";
		File dirFile = new File(path);
		if (!dirFile.exists()) {
			dirFile.mkdir();
		}

		File myCaptureFile = new File(path + fileName);
		BufferedOutputStream bos = new BufferedOutputStream(
				new FileOutputStream(myCaptureFile));
		bm.compress(Bitmap.CompressFormat.JPEG, 90, bos);
		bos.flush();
		bos.close();
	}

	public String getSDPath() {
		File sdDir = null;
		boolean sdCardExist = Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
		if (sdCardExist) {
			sdDir = Environment.getExternalStorageDirectory();// 获取跟目录
		} else {
			sdDir = getFilesDir();
		}
		return sdDir.toString();
	}

	private RequestCallBack<String> callBackHeadimg = new RequestCallBack<String>() {

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {

			String json = responseInfo.result;
			// 使用Gson把json解析成对象
			// 1 得到gson对象
			Gson gson = new Gson();
			// 2 使用gson对象的方法
			// NewsColumnResp newsColumnResp = gson.fromJson(json,
			// NewsColumnResp.class);
			Log.d("test", "上传成功" + json);
			Toast.makeText(MineConversationInfo.this, "上传成功", 0).show();

			SPUtils.put(MineConversationInfo.this, "RongIMNeedRefresh", true);

			ResreshHeadimgRsq resreshHeadimgRsq = gson.fromJson(json,
					ResreshHeadimgRsq.class);
			user_headimg = resreshHeadimgRsq.userimg;
			Log.e("test", "刷新   ===" + json);
			Log.e("test", "刷新   ===" + user_headimg);
			String userid = SPUtils.getString(MineConversationInfo.this,
					ConfigConstant.USERNAME);
			try {
				RongIM.getInstance()
						.refreshUserInfoCache(
								new UserInfo(userid, username, Uri
										.parse(user_headimg)));
				RongIM.getInstance()
						.setCurrentUserInfo(
								new UserInfo(userid, username, Uri
										.parse(user_headimg)));
			} catch (Exception e) {
				// TODO: handle exception
			}

			SPUtils.put(MineConversationInfo.this, "RongIMusername", username);
			SPUtils.put(MineConversationInfo.this, "userheadimg", user_headimg);

		}

		@Override
		public void onFailure(HttpException error, String msg) {
			// Toast.makeText(MainActivity.this, "onFailure", 0).show();
			// Log.d("test", "" + error.getMessage());
		}
	};
	public ArrayList<friendInfo> friendlist = new ArrayList<friendInfo>();
	public ArrayList<UserInfo> UserList = new ArrayList<UserInfo>();
	public ArrayList<Group> GroupList = new ArrayList<Group>();
	private int grouplist_count = 0;
	private ConversationListResq mConversationListResq = new ConversationListResq();
	Callback callBackRefresh = new Callback() {

		@Override
		public void onResponse(Response arg0) throws IOException {
			// TODO Auto-generated method stub

		}

		@Override
		public void onFailure(Request arg0, IOException arg1) {
			// TODO Auto-generated method stub

		}
	};
	private String userInfo;

	@TargetApi(19)
	private void setTranslucentStatus(boolean on) {
		Window win = getWindow();
		WindowManager.LayoutParams winParams = win.getAttributes();
		final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
		if (on) {
			winParams.flags |= bits;
		} else {
			winParams.flags &= ~bits;
		}
		win.setAttributes(winParams);
	}

}
